package com.mc.api.controller;

import com.alibaba.fastjson.JSONArray;
import com.mc.api.domain.CustomError;
import com.mc.api.domain.SysDictData;
import com.mc.api.service.impl.DataModelImpl;
import com.mysql.cj.x.protobuf.MysqlxCrud;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/dataModel")
public class DataModelController {

    @Autowired
    DataModelImpl dataModel;

    @PostMapping("/info")
    @ResponseBody
    public Object info(@RequestBody SysDictData dictData){
        CustomError error = new CustomError();
        if(dictData.getLastUpdateTime()==null||"".equals(dictData.getLastUpdateTime())){
            error.setCode("500");
            error.setMsg("时间不能为空");
            return JSONArray.toJSON(error);
        }
        try{
            Date lastSynDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dictData.getLastUpdateTime());
            return JSONArray.toJSON(dataModel.SelectDictDataBy(dictData));
        }catch (ParseException e){
            error.setCode("500");
            error.setMsg("时间格式异常");
            return JSONArray.toJSON(error);
        }
    }
}
